/**
 * Created by zhenggongbu on 2016-04-11.
 */
var myDB = require ("mysql");
////打开数据库
function openConnection(){
      myconnection = myDB.createConnection({ //创建数据库连接，包含了执行规则，获取数据库连接对象
        host:"localhost",   //主机名字
        user:"root",    //数据库账号
        password:"root",    //数据库密码
        port: '3306',
        database: 'baijie84'
    });
    //打开操作数据库的通道,打开连接
    return myconnection;
}
exports.checknews=function(request,response){
    var title1_news = request.body.title1_news;
    console.log("进入dao");
    var myconnect = openConnection();
    myconnect.connect();
    myconnect.query('SELECT * FROM hc_infomation  LEFT JOIN hc_infoimgs_reference ON(hc_infomation.article_id = hc_infoimgs_reference.article_id)  LEFT JOIN hc_user ON(hc_user.user_id=hc_infomation.user_id)  GROUP BY hc_infomation.article_id  ORDER BY publish_date DESC',[null],function(err,data){
        response.send(JSON.stringify(data));
        console.log(data);
    });
    myconnect.end();
};
exports.checknews2=function(request,response){
    var title1_news = request.body.title1_news;
    console.log("进入dao");
    var myconnect = openConnection();
    myconnect.connect();
    myconnect.query('SELECT * FROM hc_infomation  LEFT JOIN hc_infoimgs_reference ON(hc_infomation.article_id = hc_infoimgs_reference.article_id)  LEFT JOIN hc_user ON(hc_user.user_id=hc_infomation.user_id) GROUP BY hc_infomation.article_id ORDER BY parise_number DESC',[null],function(err,data){
        response.send(JSON.stringify(data));
        console.log(data);
        console.log("3333333");
    });
    myconnect.end();
};

exports.Viewdetails=function(request,response){
    var title1_news = request.body.title1;
    console.log("进入dao-viewdetail");
    console.log(title1_news);
    var myconnect = openConnection();
    myconnect.connect();
    myconnect.query("SELECT * FROM hc_infomation  LEFT JOIN hc_infoimgs_reference ON(hc_infomation.article_id = hc_infoimgs_reference.article_id)  LEFT JOIN hc_user ON(hc_user.user_id=hc_infomation.user_id) WHERE hc_infomation.article_id=? ",title1_news,function(err,data){
        response.send(JSON.stringify(data));
        //console.log(data);
    });
    myconnect.end();
};
exports.Viewdetails2=function(request,response){
    var title1_news = request.body.title2;
    console.log("进入dao-viewdetail2");
    console.log(title1_news);
    var myconnect = openConnection();
    myconnect.connect();
    myconnect.query("SELECT * FROM hc_infomation  LEFT JOIN hc_infoimgs_reference ON(hc_infomation.article_id = hc_infoimgs_reference.article_id)  LEFT JOIN hc_user ON(hc_user.user_id=hc_infomation.user_id) WHERE hc_infomation.article_id=? ",title1_news,function(err,data){
        response.send(JSON.stringify(data));
        console.log(data);
        console.log(data);
    });
    myconnect.end();
};